<template>
  <div  class="message-container">
    <div v-if="messageList.length>0">
      <div class="item" v-for="(item, index) in messageList" :key="index">
      <div class="title">{{ item.title }}</div>
      <div>({{ item.createDate }})</div>
      <div class="content">{{ item.content }}</div>
      <div class="button"> 
        <el-button type="info" size="small" @click="View(item)">{{$ts('查看')}}</el-button>
        <!-- <el-button>删除</el-button> -->
      </div>
    </div>
    </div>
    <div v-else>
      {{$ts('暂无消息')}}
    </div>
    <MessageVolbox v-if="isChildVisible" @callParentMethod="parentMethod" ref="childRef" />
  </div>
</template>

<script>
import api from "../../api/api";
import MessageVolbox from "./MessageVolbox.vue";
export default {
  components:{MessageVolbox},
  props: {
    list: {
      type: Array,
      default: () => {
        return [];
      }
    }
  },
  data(){
    return{
      isChildVisible: false,
      messageList:[],
    }
  },

  created() {
    this.getlist()
  },
  methods:{
    parentMethod(){
      // console.log('父组件')
    },
    View(val){
      this.isChildVisible=true;
      this.$nextTick(() => {
        if (this.$refs.childRef) {
          this.$store.getters.data().Message=this;
          this.$refs.childRef.open(val);
        }
      });
    },
    async getlist(){
      let result= await api.GetMessageList()
      if(result.status){
        this.messageList=result.data
      }else{
        this.messageList=[]
      }
      
    }
  }
};
</script>
<style scoped lang="less">
.message-container {
  .title {
    padding-bottom: 10px;
  }
  .item {
    border-bottom: 1px solid #eee;
    padding: 10px 20px;
  }
  .content {
    color: #7e7e7e;
    font-size: 13px;
  }
  .button{
    margin-top: 15px;
  
    display: flex;
  }
}
</style>
